<!--
 * @Description: 砍价活动受邀人列表
 * @Author: liyujie
 * @Date: 2021/2/23
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/2/23
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    受邀人管理列表
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        用户姓名/编号/电话
                    </p>
                    <el-input
                        placeholder="搜索用户姓名/编号/电话"
                        v-model="filterData.keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->

            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
                class="data-table"
                v-loading="tableLoading"
            >
                <el-table-column
                    label="序号"
                    align="center"
                    width="80"
                    type="index"
                />
                <el-table-column
                    prop="true_name"
                    label="姓名"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="student_no"
                    label="用户编号"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="phone"
                    label="联系方式"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="school_name"
                    label="学校名称"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="类型"
                    align="left"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div v-if="scope.row.aim_type === 'goods'">商品</div>
                        <div v-if="scope.row.aim_type === 'platform_coupon'">平台优惠券</div>
                        <div v-if="scope.row.aim_type === 'merchant_coupon'">商家优惠券</div>
                        <div v-if="scope.row.aim_type === 'red_packet'">平台红包</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="用户类别"
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div>{{ scope.row.is_new_user ? '新用户' : '老用户' }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="bargain_money"
                    label="砍价金额"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="是否额外奖励"
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div>{{ Number(scope.row.new_user_bargain_money) > 0 ? '是' : '否' }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="砍价时间"
                    align="left"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="是否发起砍价"
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div>{{ scope.row.is_join_this_activity ? '是' : '否' }}</div>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'BargainActivityInvitedList',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                apply_no: '',
                keyword: '',
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            authResult: {}
        };
    },
    computed: {},
    watch: {},
    filters: {
    },
    mounted() {
        let query = this.$route.query;

        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: '砍价活动'},
            {title: '发起人管理', path: `/student/bargain-activity-initiator-list?bargain_no=${query.bargain_no ? query.bargain_no : ''}`},
            {title: '受邀人管理'}
        ]);
        this.filterData.apply_no = query.apply_no;
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/shop_tool_bargain%5Capply%5Cget_help_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        padding: 24px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                margin-bottom: 24px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            margin-top: 24px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 24px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }

        /* 分页 */

        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
}
</style>

